<template>
	<h4 />
  <el-table :data="trials" stripe style="width:700px;margin:0 auto;margin-top:30px" border :row-style="tableRowStyle"
    :header-cell-style="tableHeaderColor" :height="tableHeight">
    <el-table-column prop="trialId" label="实习工号" width="100" height="50" header-align="center" align="center" />
    <el-table-column prop="trialName" label="姓名" width="100" height="50" header-align="center" align="center"/>
    <el-table-column prop="trialEntryTime" label="试用期开始时间" height="50" width="200" header-align="center" align="center"/>
	<el-table-column prop="trialWorkTime" label="试用期时长" width="100" height="50" header-align="center" align="center"/>
	<el-table-column prop="opeartion" label="操作" width="200" height="50" header-align="center" align="center">
		<template #default="scope">
			<el-button @click="openUpdate(scope.row)">
				<el-icon><Checked /></el-icon>
			</el-button>
			<el-button @click="">
				<el-icon><EditPen /></el-icon>
			</el-button>
			<el-button><el-icon><Delete /></el-icon></el-button>
		</template>
	</el-table-column>
	
  </el-table>
  
  <!-- 点击通过按钮，出现对话框，生成默认的值实习工号，姓名，联系电话 -->
  <!-- 填写关于转正的信息 -->
  <el-dialog v-model="updateTrialToEmploy" center title="员工转正信息填写表">
	  <el-form
		:label-position="labelPostition"
		label-width="100px"
		style="max-width: 350px;margin: 0px auto;"
	  >
		  <el-form-item label="试用期工号:">
		  	  <el-input disabled v-model="updateTrial.trialId" />
		  </el-form-item>
		  <el-form-item label="姓名:">
		  	  <el-input disabled v-model="updateTrial.trialName" />
		  </el-form-item>
		  <el-form-item label="联系电话:">
		  	  <el-input type="number" v-model="updateTrial.ePhone" />
		  </el-form-item>
		  <el-form-item label="工作部门:">
		  	  <el-select v-model="updateTrial.dpId" placeholder="选择部门">
		  	      <el-option v-for="d in depts" :value="d.dpId" :label="d.dpName" />
		  	  </el-select>
		  </el-form-item>
		  <el-form-item label="工作岗位:">
		  	  <el-select @click="selectPost" type="number" v-model="updateTrial.pstId" placeholder="选择岗位">
		  	      <el-option v-for="e in posts" :value="e.pstId" :label="e.pstName" />
		  	  </el-select>
		  </el-form-item>
		  <el-form-item label="月薪:">
		  	  <el-input type="number" v-model="updateTrial.eMoney" />
		  </el-form-item>
		  <el-form-item label="年假时长:">
		  	  <el-input type="number" v-model="updateTrial.eAnnualVac" />
		  </el-form-item>
		  <el-form-item>
		      <el-button type="primary" @click="toEmployee">转正</el-button>
			  <el-button type="primary" @click="updateTrialToEmploy=false">取消</el-button>
		  </el-form-item>
		</el-form>
  </el-dialog>
</template>

<script>
	import qs from 'qs'
	import {ElMessage} from 'element-plus'
	export default{
		data(){
			return{
				trials:[],
				depts:[],
				posts:[],
				updateTrialToEmploy:false,
				updateTrial:{
					eId:this.trialId
				}
			}
		},
		methods: {
			createTrial(){
				let that=this
				this.$axios.get("http://localhost:8080/trial/employ0").then(function(rest){
				that.trials=rest.data
				console.log(that.trials)
				})
			},
			openUpdate(row){
				this.updateTrial=row
				this.updateTrialToEmploy=true
			},
			toEmployee(){
				let that=this
				let strs=qs.stringify(that.updateTrial)
				console.log(that.updateTrial)
				this.$axios.get("http://localhost:8080/trial/isEmploy?"+strs.trialId).then(function(resut){
					console.log(resut)
					if(resut!=0)
					{
						ElMessage({
							showClose: true,
							message: '恭喜转正成功1',
							type: 'success',
						})
						that.updateTrialToEmploy=false
						that.createTrial()
						console.log(1)
					}
					else
					{
						ElMessage({
							showClose: true,
							message: '发生了失败，快去找找错误1',
							type: 'error',
						})	
						console.log(2)
					}
				})
				this.$axios.get("http://localhost:8080/employee/insertfromtrial?"+strs).then(function(resift){
					console.log(strs)
					if(resift!=0)
					{
						ElMessage({
							showClose: true,
							message: '恭喜转正成功2',
							type: 'success',
						})
						that.updateTrialToEmploy=false
						that.createTrial()
						console.log(3)
					}
					else
					{
						ElMessage({
							showClose: true,
							message: '发生了失败，快去找找错误2',
							type: 'error',
						})	
						console.log(4)
					}
				})
			},
			selectPost(){
				let that=this
				let strr=qs.stringify(that.updateTrial)
				console.log(that.updateTrial)
				this.$axios.get("http://localhost:8080/post/selectPostListByDept?"+strr).then(function(ressp){
					that.posts=ressp.data
					console.log(ressp)
					if(ressp.data!=null&&ressp.data!='')
					{
						console.log(ressp)
					}
					else
					{
						console.log("bbbbbs")
					}
				})
			}
		},
		created(){
			this.updateTrialToEmploy=false
			this.createTrial()
			let that=this
			this.$axios.get("http://localhost:8080/dept/selectDeptList").then(function(ressd){
				that.depts=ressd.data
				console.log(ressd)
				if(ressd.data!=null&&ressd.data!='')
				{
					console.log(ressd)
				}
				else
				{
					console.log("bbbbbs")
				}
			})
		}
	}
</script>

<style>
	.el-table-column{
		text-align:center
	}
	.el-main{
		line-height:50px;
	}
</style>